package com.zhitong.money.mapper;

import com.zhitong.money.entity.PSalaryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface PSalaryParamMapper {

    @Results(id = "paramMap",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "basic_salary",property = "basicSalary"),
            @Result(column = "full_attention",property = "fullAttention"),
            @Result(column = "subsidy",property = "subsidy"),
            @Result(column = "position_salary",property = "positionSalary"),
            @Result(column = "overtime_salary",property = "overtimeSalary"),
            @Result(column = "leave_deduction",property = "leaveDeduction"),
            @Result(column = "late_deduction",property = "lateDeduction"),
            @Result(column = "other_deduction",property = "otherDeduction")
    })
    @Select({
            "<script>",
            "select * from p_salary_param",
            "<if test='pids!=null'>",
            "where pid in",
            "<foreach item='item' collection='pids' open='(' close=')' separator=','>",
            "#{item}",
            "</foreach>",
            "</if>",
            "</script>"
    })
    public List<PSalaryParam> findPSalaryParamByMap(Map<String,Object> map);

    @ResultMap("paramMap")
    @Select("select * from p_salary_param where pid = #{pid}")
    public PSalaryParam findPSalaryParamByPid(String pid);

    @Select("select pid from p_salary_param")
    public List<String> findAllPids();

    @ResultMap("paramMap")
    @Select("select * from p_salary_param where pid in (select pid from employee where tellerId =#{tid})")
    public PSalaryParam findParamByTid(String tid);

    @Select({
            "<script>",
            "select * from p_salary_param",
            "where pid in ",
            "<foreach item='item' collection='pids' separator=',' open='(' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    public List<String> findIdsByPids(List<String> pids);

    @ResultMap("paramMap")
    @Select("select * from p_salary_param where id = #{id}")
    public PSalaryParam findPsalaryParamById(String id);

    @Insert("insert into p_salary_param values(#{id},#{pid},#{basicSalary}," +
            "#{fullAttention},#{subsidy},#{positionSalary},#{overtimeSalary}," +
            "#{leaveDeduction},#{lateDeduction},#{otherDeduction})")
    public void addPSalaryParam(PSalaryParam pSalaryParam);

    @Update({
            "<script>",
            "update p_salary_param",
            "<trim prefix='set' suffixOverrides=','>",
            "<if test='pid!=null and pid!=\"\"'> pid=#{pid},</if>",
            "<if test='basicSalary!=null'> basic_salary=#{basicSalary},</if>",
            "<if test='fullAttention!=null'> full_attention=#{fullAttention},</if>",
            "<if test='subsidy!=null'> subsidy=#{subsidy},</if>",
            "<if test='positionSalary!=null'> position_salary=#{positionSalary},</if>",
            "<if test='overtimeSalary!=null'> overtime_salary=#{overtimeSalary},</if>",
            "<if test='leaveDeduction!=null'> leave_deduction=#{leaveDeduction},</if>",
            "<if test='lateDeduction!=null'> late_deduction=#{lateDeduction},</if>",
            "<if test='otherDeduction!=null'> other_deduction=#{otherDeduction},</if>",
            "</trim>",
            "where id = #{id}",
            "</script>"
    })
    public void updatePSalaryParam(PSalaryParam pSalaryParam);

    @Delete("delete from p_salary_param where id =#{id}")
    public void delPSalaryParam(String id);

    @Delete({
            "<script>",
            "delete from p_salary_param",
            "where id in ",
            "<foreach item='item' collection='ids' separator=',' open='(' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    public void delPSalaryByIds(List<String> ids);

    @Delete({
            "<script>",
            "delete from p_salary_param",
            "where pid in ",
            "<foreach item='item' collection='pids' separator=',' open='(' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    public void delPSalaryByPids(List<String> pids);

}
